﻿using System;
using System.Text;
using Portal.Core.Utils;
using Portal.Data.Webparts;

public partial class Webparts_Templates_truyen_Alphabet : WebpartControl
{
    private const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        if (!IsPostBack)
        {
            if (Request.Url.LocalPath.IndexOf("/admin", StringComparison.OrdinalIgnoreCase) >= 0)
                return;
            var current = Request["c"];

            var sb = new StringBuilder();
            sb.Append("<div class='alphabet'>");
            sb.Append(string.Format("<h3>{0}</h3>", Config.DisplayTitle));
            sb.Append("<ul>");
            var urlNonePaging = Process.AddParam("page", null);
            foreach (char c in chars)
            {
                string selected;
                if (current != null && c.ToString() == current)
                    selected = "class='selected'";
                else
                    selected = "";

                sb.Append(string.Format("<li {2} onclick=\"location.href='{0}'\">{1}</li>", Process.AddParam(urlNonePaging, "c", c), c, selected));
            }
            sb.Append(string.Format("<li onclick=\"location.href='{0}'\">Tất cả</li>", Process.AddParam(urlNonePaging, "c", null)));
            sb.Append("</ul><br class='clear'/>");
            sb.Append("</div>");
            writer.Write(sb.ToString());
        }
    }
}